package com.ccys.db.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


@Mapper
public interface CommonMapper {

    /**
     * 根据库名和表名获取表结构和字段注释
     *
     * @param libraryName
     * @param tableName
     * @return
     */
    List<Map<String, Object>> getDataInfo(@Param("libraryName") String libraryName, @Param("tableName") String tableName);

    /**
     * 根据库名和表名获取表注释
     *
     * @param libraryName
     * @param tableName
     * @return
     */
    String getTableComment(@Param("libraryName") String libraryName, @Param("tableName") String tableName);


    @Update("update ${tableName} set ${columnName} = ${columnName} + #{num} where id = #{id}")
    int addNum(@Param("tableName") String tableName,
               @Param("columnName") String columnName,
               @Param("id") String id,
               @Param("num") Integer num);

    @Update("update ${tableName} set ${columnName} = ${columnName} - #{num} where id = #{id} and ${columnName} >= #{num}")
    int subNum(@Param("tableName") String tableName,
               @Param("columnName") String columnName,
               @Param("id") String id,
               @Param("num") Integer num);

    /**
     * 使用不了insertList方法替代
     *
     * @param sql
     * @return
     */
    @Insert("${sql}")
    int doSql(@Param("sql") String sql);
}
